package com.lsu.component.practice;

import java.util.List;

/**
 * 场景类
 *
 * @Author wang suo
 * @Date 2020/12/22 0022 11:22
 * @Version 1.0
 */
public class Client {
    public static void main(String[] args) {
        // 首先产生一个根节点
        IRoot ceo = new Root("王大麻子", "总经理", 100000);
        // 产生 3 个部门经理
        Branch developDep = new Branch("刘大瘸子", "研发部门经理", 10000);
        Branch salesDep = new Branch("马二拐子", "销售部门经理", 20000);
        Branch financeDep = new Branch("赵三驼子", "财务部门经理", 30000);
        // 开发部门的3个小组长
        IBranch firstDevGroup = new Branch("杨三乜斜", "开发一组组长", 5000);
        IBranch secondDevGroup = new Branch("吴大棒槌", "开发二组组长", 6000);

        // 剩下的就是我们这些小兵了,就是路人甲，路人乙
        ILeaf a = new Leaf("a", "开发人员", 2000);
        ILeaf b = new Leaf("b", "开发人员", 2000);
        ILeaf c = new Leaf("c", "开发人员", 2000);
        ILeaf d = new Leaf("d", "开发人员", 2000);
        ILeaf e = new Leaf("e", "开发人员", 2000);
        ILeaf f = new Leaf("f", "开发人员", 2000);
        ILeaf g = new Leaf("g", "开发人员", 2000);
        ILeaf h = new Leaf("h", "销售人员", 5000);
        ILeaf i = new Leaf("i", "销售人员", 4000);
        ILeaf j = new Leaf("j", "财务人员", 5000);
        ILeaf k = new Leaf("k", "CEO秘书", 8000);
        ILeaf zhengLaoLiu = new Leaf("郑老六", "研发部副总", 20000);

        // 该产生的人都产生出来了，然后我们怎么组装这棵树
        // 首先是定义总经理下有三个部门经理
        ceo.add(developDep);
        ceo.add(salesDep);
        ceo.add(financeDep);
        // 总经理下还有一个秘书
        ceo.add(k);

        // 定义研发部门下的结构
        developDep.add(firstDevGroup);
        developDep.add(secondDevGroup);
        // 研发部经理下还有一个副总
        developDep.add(zhengLaoLiu);

        // 看看开发两个开发小组下有什么
        firstDevGroup.add(a);
        firstDevGroup.add(b);
        firstDevGroup.add(c);
        secondDevGroup.add(d);
        secondDevGroup.add(e);
        secondDevGroup.add(f);

        // 再看销售部下的人员情况
        salesDep.add(h);
        salesDep.add(i);

        //最后一个财务
        financeDep.add(j);

        //树状结构写完毕，然后我们打印出来
        System.out.println(ceo.getInfo());

        //打印出来整个树形
        getAllSubordinateInfo(ceo.getSubordinateInfo());
    }

    /**
     * 遍历并打印整个树
     *
     * @param subordinateList 树或子树
     */
    private static void getAllSubordinateInfo(List subordinateList) {
        for (Object o : subordinateList) {
            if (o instanceof Leaf) {
                System.out.println(((Leaf) o).getInfo());
            } else {
                IBranch branch = (IBranch) o;
                System.out.println(branch.getInfo());
                // 递归调用
                getAllSubordinateInfo(branch.getSubordinateInfo());
            }
        }
    }
}
